package com.marver.common.result;

import java.io.Serializable;

import com.marver.common.Global;

import javax.persistence.Transient;

/**
 * Created by marver on 2017/7/3 14:43.
 * 分页相关参数
 */
public class Page implements Serializable {
    private static final long serialVersionUID = 1L;
    @Transient
    private int pageNum;        //当前页号
    @Transient
    private int pageSize;       //页面显示条数
    @Transient
    private long total;         //总条数
    @Transient
    private int pages;           //总页数
//    private boolean hasPreviousPage;    //是否有前一页
//    private boolean hasNextPage;         //是否有下一页

    public Page(){
    	
    }
    
    public Page(int pageNum,int pageSize,long total){
    	this.setPageNum(pageNum);
    	this.setTotal(total);
    	this.setPageSize(pageSize);
    }
    
    public int getPageNum() {
        return (pageNum<0?1:pageNum);
    }

    public void setPageNum(int pageNum) {
        this.pageNum = (pageNum<0?1:pageNum);
    }

    public int getPageSize() {
        return (pageSize<=0?Global.defaultPageSize:pageSize);
    }

    public void setPageSize(int pageSize) {
        this.pageSize = (pageSize<=0?Global.defaultPageSize:pageSize);
        if(this.total>this.pageSize){
        	this.pageSize=(int)this.total;
        }
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    	if(this.total>0&&pages<=0){
	    	this.pages=(int) (this.getTotal()/this.getPageSize());
	    	if (this.getTotal()%this.getPageSize()>0) {
	    		this.pages++;
	        }
    	}
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }
}
